package org.androidpn.adapter;

import java.util.List;

import org.androidpn.R;
import org.androidpn.adapter.TagGridViewAdapter.ViewHodler;
import org.androidpn.model.CUserInfo;
import org.androidpn.utils.ConstanceUtil;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SearchResultLvAdapter extends BaseAdapter {
	private Context context;
	private List<CUserInfo> cUserInfos;
    public void setcUserInfos(List<CUserInfo> cUserInfos) {
		this.cUserInfos = cUserInfos;
	}
public SearchResultLvAdapter(Context context){
	this.context =context;
}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return cUserInfos.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return cUserInfos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHodler viewHodler;
		if(arg1 ==null){
			arg1=View.inflate(context, R.layout.recommend_gv_item, null);
			viewHodler =new ViewHodler();
			viewHodler.tvName =(TextView) arg1.findViewById(R.id.tv_name);
			viewHodler.ivHead =(ImageView) arg1.findViewById(R.id.iv_head);
			arg1.setTag(viewHodler);
		}else{
		    viewHodler =(ViewHodler) arg1.getTag();
		}
		DisplayImageOptions options1 = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true)
				.considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565)
				.showImageOnFail(R.drawable.default_icon)
				.showImageForEmptyUri(R.drawable.default_icon)
				.showImageOnLoading(R.drawable.default_icon).build();
		ImageLoader.getInstance().displayImage(ConstanceUtil.HOST_NAME+cUserInfos.get(arg0).getIcon(), viewHodler.ivHead, options1);
		viewHodler.tvName.setText(cUserInfos.get(arg0).getName());
		
		return arg1;
	}
	
	
class ViewHodler{
	TextView tvName;
	ImageView ivHead;
}

}
